using System;

#if MF_FRAMEWORK_VERSION_V4_2
using Microsoft.SPOT;
#endif

namespace MLRobotic.IA.Utils
{
    public static class MathExt
    {
#if MF_FRAMEWORK_VERSION_V4_2
        public static int Cos(int angle)
        {
            return Microsoft.SPOT.Math.Cos(angle);
        }

        public static int Sin(int angle)
        {
            return Microsoft.SPOT.Math.Sin(angle);
        }
#else
        public static int Cos(int angle)
        {
            return (int)(Math.Cos(angle) * 1000);
        }

        public static int Sin(int angle)
        {
            return (int)(Math.Sin(angle) * 1000);
        }
#endif

        // Round ]-0.5;0.5] to 0 instead of [-0.5;0.5]
        public static double RoundFloor(double d)
        {
            double r = System.Math.Round(d);

            if ((d - r) == -0.5)
                r -= 1;

            return r;
        }
    }
}
